
from flask import Flask, render_template, request
import os
from mysql_storage import storage
from mysql_insert import mysql_insert
from mysql_select import mysql_select
from gevent import pywsgi
import json

template_path = os.path.join('templates')
app = Flask(__name__,template_folder=template_path)


@app.route('/')
def hello_world():  # put application's code here
    return 'Hello Wrld!'

@app.route('/hhh')
def world():  # put application's code here
    return 'qqqqqqqqqqqqq'

@app.route('/a', methods=['GET', 'POST'])
def a():  # put application's code here
    print('bbb')
    q = 'cg'

    if request.method == 'POST':
        print(request.form)
        # request_dict = request.form.to_dict()
        #
        # print(request_dict)
        # number = request_dict['th']
        # type  = request_dict['zl']
        # name = request_dict['mc']
        # size = request_dict['cc']
        # quantity = request_dict['sl']
        # mysql_insert(get_number=number,get_type=type,get_name=name,get_size=size,get_quantity=quantity)
        storage_list = storage()
        print(storage_list)
        print('------------------')
        return list(storage_list)

    elif request.method == 'GET':
        storage_list = storage()
        print(storage_list)
        print(request.method)
        storage_list = list(storage_list)
        print(storage_list)
        print('------------------')

    else:
        print('sb')


    return render_template('storage.html')

@app.route('/b', methods=['GET', 'POST'])
def b():  # put application's code here


    if request.method == 'POST':

        request_dict = request.form.to_dict()
        print(request_dict)
        size_result = request_dict['data']
        print(size_result)
        print(request.method)
        storage_list = mysql_select(get_size=size_result)
        print(storage_list,type(storage_list))
        return list(storage_list)
    elif request.method == 'GET':
        print(request.data)
        print(request.method)
    else:
        print('sb')


    return render_template('select.html')



if __name__ == '__main__':
    app.run()
    server = pywsgi.WSGIServer(('127.0.0.1', 5000), app)
    server.serve_forever()
